from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render

# 用于存储文本的全局变量
backend_text = ""

def index(request):
    return render(request, 'ui0.html')

@csrf_exempt
def set_text(request):
    global backend_text
    if request.method == 'POST':
        import json
        data = json.loads(request.body.decode())
        backend_text = data.get('text', '')
        return JsonResponse({'status': 'ok', 'text': backend_text})
    return JsonResponse({'status': 'fail'}, status=400)

def get_text(request):
    global backend_text
    return JsonResponse({'text': backend_text})